<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
    <title>添加员工</title>
    <script src="__INDEX__/store/js/mui.min.js"></script>
	<link href="__INDEX__/store/css/mui.min.css" rel="stylesheet" />
	<link rel="stylesheet" href="__INDEX__/store/css/style.css" />
	<link rel="stylesheet" href="__INDEX__/store/css/newsj.css" /> 
	<link rel="stylesheet" href="__INDEX__/store/css/sjhout.css" />
    <link rel="stylesheet" href="__INDEX__/store/css/css.css" /> 
    <script type="text/javascript" charset="utf-8">
      	mui.init();
    </script>
    
    <style>
    	.mui-checkbox input[type=checkbox]:checked:before, .mui-radio input[type=radio]:checked:before {
			color: #D6AA50;
		}
		.chongz_btn{
			background: #1DAA39;
		}
		.mui-checkbox input[type=checkbox]:checked:before, .mui-radio input[type=radio]:checked:before{
			color: #1DAA39;
		}
    </style>
</head>
<body>
	<header class="mui-bar mui-bar-nav">
	    <a class="mui-icon mui-icon-left-nav mui-pull-left" href="JavaScript:history.go(-1)"></a>
	    <h1 class="mui-title">添加员工</h1>
	</header>
		<div class="mui-content">
			<ul class="tjsyy_list">
				<li class="clearfix">
					<span class="left">员工会员ID</span>
					<input type="text"  value="{$agent_id}" id="agent_id" style="display: none;">
					<span class="right"><input type="text" placeholder="请填写员工会员ID" name='no' id='no'></span>
				</li>
				<li class="clearfix">
					<span class="left">员工手机号</span>
					<span class="right"><input type="text" placeholder="请填写员工手机号" name='mobile' id='mobile'></span>
				</li>
				<li class="clearfix">
					<span class="left">密码</span>
					<span class="right"><input type="text" placeholder="请填写密码" name='password' id='password'></span>
				</li>
			</ul>
			<ul class="tjsyy_list">
				<li class="clearfix">
					<span class="left">姓名</span>
					<span class="right"><input type="text" placeholder="请填写真实姓名" name='name' id='name'></span>
				</li>
				<li class="clearfix" onclick="search_zhiwei()">
					<span class="left">职位</span>
					<span class="right"><input type="text" placeholder="员工/店长" name='z_name' id='z_name'></span>
					<input style="display: none;" type="text"  name='z_id' id='z_id'>
				</li>
				<!--<li class="clearfix" onclick="search_chain()">
					<span class="left">所属门店</span>
					<span class="right"><input placeholder="所属门店" type="text" name='chain_name' id='chain_name'></span>
					<input type="hidden" name='chain_id' id='chain_id'>
				</li>-->
			</ul>
			<button type="button" class="tjsyy_btn">提交申请</button>		
		</div>
	
	<!--连锁店界面-->
	<div id="search_chain" style="position:fixed;background-color:#efeff4;top:0;left:0;right:0;bottom:0;display: none;z-index: 1000;">
	<header class="mui-bar mui-bar-nav">
	    <a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a>
	    <h1 class="mui-title">选择门店</h1>
	</header>
		<div class="mui-content">
			<div class="jiaoban_btbox clearfix">
				<div class="name">店铺名称</div>
				<div class="phonenum">地址</div>
				<div class="choice">选择</div>
			</div>
			<form class="mui-input-group jiaoban_memlist" id="chain_list">
			
			</form>
		</div>
		<button id='create_emp' class="chongz_btn qr">确定</button>		
	</div>
	
	<!--职位界面-->
	<div id="search_zhiwei" style="position:fixed;background-color:#efeff4;top:0;left:0;right:0;bottom:0;display: none;z-index: 1000;">
		<header class="mui-bar mui-bar-nav">
		    <a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a>
		    <h1 class="mui-title">选择职位</h1>
		</header>
		<div class="mui-content">
			<div class="jiaoban_btbox clearfix">
				<div class="name">职位名称</div>
				<div class="right">选择</div>
			</div>
			<form class="mui-input-group jiaoban_memlist" id="zhiwei_list">
				<div class="mui-input-row mui-radio clearfix">
					<div class="name">员工</div>
					<div class="right"><input name="radio2" value='1' dataname = '员工' type="radio"></div>
				</div>
				<div class="mui-input-row mui-radio clearfix">
					<div class="name">店长</div>
					<div class="right"><input name="radio2" value='2' dataname = '店长' type="radio"></div>
				</div>
			</form>
		</div>
		<button id='create_emp' class="chongz_btn zwqr">确定</button>	
	</div>
</body>
</html>
<script type="text/javascript" src="__INDEX__/store/js/jquery.min.js"></script>
<script type="text/javascript" src="__INDEX__/store/js/castapp.js"></script>
<script type="text/javascript" src="__INDEX__/store/js/layer/layer.min.js"></script>
<script type="text/javascript" src="__INDEX__/store/js/picker.js"></script>
<script type="text/javascript" src="__INDEX__/store/js/city.data-3.js"></script>
<script type="text/javascript" src="__INDEX__/store/js/bootstrap.min.js"></script>
<script type="text/javascript" src="__INDEX__/store/js/app.js"></script>
<script> 
	//选择所属门店
	function search_chain(){
		$("#search_chain").show();
		
		$.ajax({
			type:"post",
			url: 'get_chainstore',
			data:{
				agent_id: $("#agent_id").val()
			},
			success:function(data){				
				var chianlist = data.chianlist;
				if(chianlist){
					var html="";
					for(var i in chianlist){
						var e = chianlist[i];
						html+='<div class="mui-input-row mui-radio clearfix">'+
						'<div class="name">'+e.store_name+'</div>'+
						'<div class="phonenum">'+e.addres+'</div>'+
						'<div class="choice"><input name="radio1" value='+e.id+' dataname = '+ e.store_name+' type="radio"></div>'+
						'</div>';
					}
					$("#chain_list").html(html);
				}
			}
		});
	}
	
	//所属门店隐藏
	$("#chainhide").click(function(){
		$("#search_chain").hide();
	})
	
	//确认连锁店
	$(".qr").click(function(){
		var val = $('input:radio[name="radio1"]:checked').val();
		var chain_name = $('input:radio[name="radio1"]:checked').attr("dataname");
		if(val==null||val==''){
			layer.msg("请选择门店");
			return false;
		}
		$("#chain_name").val(chain_name);
		$("#chain_id").val(val); 
		$("#search_chain").hide();
	});
	
	//选择职位
	function search_zhiwei(){
		$("#search_zhiwei").show();
	}
	//职位隐藏
	$("#zhiweihide").click(function(){
		$("#search_zhiwei").hide();
	})
	
	//确认职位
	$(".zwqr").click(function(){
		var val = $('input:radio[name="radio2"]:checked').val();
		var zw_name = $('input:radio[name="radio2"]:checked').attr("dataname");
		if(val==null||val==''){
			layer.msg("请选择职位");
			return false;
		}
		$("#z_name").val(zw_name);
		$("#z_id").val(val);
		$("#search_zhiwei").hide();
	});



 	$('.tjsyy_btn').click(function(){
		//员工号
		var no = $("#no").val();
		//密码
		var pwd = $("#password").val();
		//所属门店
//		var chain_id = $("#chain_id").val(); 
//		var chain_name = $("#chain_name").val();
		//职位
		var z_id = $("#z_id").val();
		//姓名
		var name = $("#name").val();
		//员工手机号
		var mobile = $("#mobile").val();
		//店铺号
		var agent_id = $("#agent_id").val();
		var myreg = /^1[3578]\d{9}$/;
		if(password=="" || name=="" || mobile=="" || no==""){
			$("#create_emp").attr('disabled',false);
			layer.msg('请把信息填写完整');
			return false;
		}
		 if(!myreg.test(mobile)){
		 	$("#create_emp").attr('disabled',false);
	    	layer.msg('请输入有效的手机号码！'); 
	    	return false;
	    }
		
		$.ajax({
			url: 'create_emp',
			data: {
				no			: no,
				pwd			: pwd,
				//chain_id	: chain_id,
				//chain_name	: chain_name,
				z_id		: z_id,
				name		: name,
				mobile		: mobile,
				agent_id	: agent_id
			},
			success: function(data) {
				if(data.code == 200) {
					layer.msg(data.msg, {
						  time: 2000 
						}, function(){
							location.href= 'employeemage.html';
						});
				}else{
					layer.msg(data.msg, {
						  time: 2000 
						}, function(){
							//location.href=APP.web_root+'shopwallet/alliance_fjlist.html';
						});
				}
			}
		});
	});
</script>